﻿using System.Collections.Generic;
using System.IO;

namespace CoverageRunner
{
    class Program
    {
        static void Main(string[] args)
        {
            // Location of VSINSTR.EXE on the build machine. This is an included program with versions of Visual Studio containing
            // the testing tools (Development and Test editions for VS2008)
            const string vsinstrLocation = @"C:\Program Files\Microsoft Visual Studio 9.0\Team Tools\Performance Tools";

            // Location to output instrumented assemblies to. VSINSTR will create an instrumented version of each target assembly
            // and put it into this location. Coverage is then run against these assemblies. 
            // Setting this to the same location as the original assemblies will result in them being overwritten with instrumented versions.
            const string outputPathForInstrumentation = @"E:\devtest\instrumentation";

            // Assemblies to instrument, including path information e.g. "E:\devtest\ClassLibrary1.dll"
            List<string> toInstrument = new List<string>();
            toInstrument.Add(@"E:\devtest\ClassLibrary1.dll");

            // The file to write coverage output to. This is normally something like "c:\mytests.coverage", and should include path information.
            const string vstsCoverageOutputFile = @"E:\devtest\instrumentation\test.coverage";
            
            // The location of the test runner (nunit.console.exe or mbunit.cons.exe for example)
            const string unitTestRunnerExecutable = @"E:\devtest\mbunit\mbunit.cons.exe";
            
            // Arguments to pass to test executable. All assemblies here should point to the ones in
            // the instrumentation directory, not the originals they were instrumented from
            string unitTestArguments = Path.Combine(outputPathForInstrumentation, "ClassLibrary1.dll");

            // Required for the VisualStudio CoverageInfoManager class. Optional, will default to the OutputPathForInstrumentationData
            const string symbolsPath = outputPathForInstrumentation;
            
            // Required for the VisualStudio CoverageInfoManager class. Optional, will default to the OutputPathForInstrumentationData
            const string exePath = outputPathForInstrumentation;
            
            // The XML file to write the .coverage (from VstsCoverageOutputFile) into.
            // This is normally something like "c:\mytests.xml", and should include path information.
            const string outputXml = @"E:\devtest\instrumentation\mytestrun2.xml";
            
            // The XSLT file to use to transform the XML output into a readable report.
            // This is normally something like "c:\coverage.xslt"
            const string coverageXslt = @"E:\devtest\coverage.xslt";
            
            // The output file for the results of the XML + XSLT transformation.
            // This is normally something like "c:\myreport.html"
            const string htmlOutputFile = @"E:\devtest\instrumentation\final.html";

            VisualStudioInstrumentation instrumentation = new VisualStudioInstrumentation(vsinstrLocation);
            instrumentation.Instrument(outputPathForInstrumentation, toInstrument);

            UnitTestRunner testRunner = new UnitTestRunner(unitTestRunnerExecutable, unitTestArguments);
            CoverageReportCreator reportCreator = new CoverageReportCreator(vstsCoverageOutputFile, symbolsPath, exePath, outputXml, coverageXslt, htmlOutputFile);
            CoverageGenerator coverageGenerator = new CoverageGenerator(vstsCoverageOutputFile, testRunner, reportCreator);

            coverageGenerator.Execute();
        }


    }
}
